package cn.edu.zjut.chopper.registry.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.edu.zjut.chopper.constant.Constant;
import cn.edu.zjut.chopper.name.NameServer;
import cn.edu.zjut.chopper.registry.RegistryContext;

/**
 * Servlet implementation class RemoteInterfaceStatisticsView
 */
public class RemoteInterfaceStatisticsView extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Log LOG = LogFactory
			.getLog(RemoteInterfaceStatisticsView.class);

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public RemoteInterfaceStatisticsView() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		NameServer nameServer = (NameServer) RegistryContext
				.get(Constant.NameServer);
		if (nameServer == null) {
			getServletContext().getRequestDispatcher("/error.jsp").forward(
					request, response);
			if (LOG.isErrorEnabled()) {
				LOG.error("can not get NameServer Instance.");
			}
			return;
		}
	}

}
